#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    void func(TreeNode* root, int* count)
    {
        if (!root)
            return;
        count[root->val - 1]++;
        func(root->left, count);
        func(root->right, count);
    }
    int numColor(TreeNode* root)
    {
        int n = 0;
        int count[1000] = { 0 };
        func(root, count);
        for (int i = 0; i < 1000; i++)
        {
            if (count[i])
                n++;
        }
        return n;
    }
};